package com.smart4soft.stock.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.smart4soft.stock.pojo.AStorage;
import com.smart4soft.stock.service.StorageService;

@Controller
@Scope("prototype")
public class StorageAction {
	
	private AStorage storage;
	
	public AStorage getStorage() {
		return storage;
	}

	public void setStorage(AStorage storage) {
		this.storage = storage;
	}

	@Resource
	private StorageService storageService;
	
	public String add() {
		storageService.save(storage);
		return "operasuccess";
	}
	
	public String updateStorageDialog(){		
		storage =  storageService.find(storage.getStorageId());
		ActionContext.getContext().put("storage", storage);
		return "update";
	}
	public String updateStorage(){
		storageService.update(storage);
		return "operasuccess";		
	}
	
	public String deleteStorage(){
		storageService.delete(storage.getStorageId());
		return "operasuccess";		
	}
	
	public String storageList() {		
		ActionContext.getContext().put("storages", storageService.getAllList());		
		return "storagelist";
	}
}
